package org.jeecg.modules.business.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.business.dto.*;
import org.jeecg.modules.business.entity.*;
import org.jeecg.modules.business.enums.BookingStatusTypeEnum;
import org.jeecg.modules.business.enums.CustomerTypeEnum;
import org.jeecg.modules.business.enums.LivingTypeEnum;
import org.jeecg.modules.business.enums.SettleTypeEnum;
import org.jeecg.modules.business.mapper.BusRoomBookingOrdersMapper;
import org.jeecg.modules.business.service.IBusDictItemService;
import org.jeecg.modules.business.service.IBusRoomBookingOrdersService;
import org.jeecg.modules.business.service.IBusRoomsLivingOrderService;
import org.jeecg.modules.business.vo.*;
import org.jeecg.modules.rooms.Vo.LivingContinueVo;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
 /**
 * @Description: 酒店预定订单
 * @Author: jeecg-boot
 * @Date:   2023-03-25
 * @Version: V1.0
 */
@Api(tags="酒店预定订单")
@RestController
@RequestMapping("/business/busRoomBookingOrders")
@Slf4j
public class BusRoomBookingOrdersController extends JeecgController<BusRoomBookingOrders, IBusRoomBookingOrdersService> {

	@Resource
	private IBusRoomsLivingOrderService roomsLivingOrderService;
	 @Autowired
	 private IBusDictItemService busDictItemService;
	/**
	 * 分页列表查询
	 *
	 * @param busRoomBookingOrders
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "酒店预定订单-分页列表查询")
	@ApiOperation(value="酒店预定订单-分页列表查询", notes="酒店预定订单-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<BusRoomBookingOrders>> queryPageList(BusRoomBookingOrders busRoomBookingOrders,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<BusRoomBookingOrders> queryWrapper = QueryGenerator.initQueryWrapper(busRoomBookingOrders, req.getParameterMap());
		Page<BusRoomBookingOrders> page = new Page<BusRoomBookingOrders>(pageNo, pageSize);
		IPage<BusRoomBookingOrders> pageList = service.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param busRoomBookingOrders
	 * @return
	 */
	@AutoLog(value = "酒店预定订单-添加")
	@ApiOperation(value="酒店预定订单-添加", notes="酒店预定订单-添加")
	//@RequiresPermissions("business:bus_room_booking_orders:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody BookingOrderSaveDto busRoomBookingOrders,String hotelId) {
		Boolean isTeam = ObjectUtil.equals(busRoomBookingOrders.getOrderInfo().getBookingOrdersType(), 2);
		busRoomBookingOrders.getOrderInfo().setBookingOrdersType(1);
		busRoomBookingOrders.getOrderInfo().setBookingStatus(1);
		return Result.OK("预定成功",service.bookingOrderSave(busRoomBookingOrders,isTeam,false,hotelId));
	}
	 /**
	  *   添加批次订单
	  *
	  * @param batchOrderSavaDto
	  * @return
	  */
	 @AutoLog(value = "酒店预定订单-添加批次订单")
	 @ApiOperation(value="酒店预定订单-添加批次订单", notes="酒店预定订单-添加批次订单")
	 //@RequiresPermissions("business:bus_room_booking_orders:add")
	 @PostMapping(value = "/add-batch")
	 public Result<String> addBatchOrder(@RequestBody BatchOrderSavaDto batchOrderSavaDto) {
		 return Result.OK("预定成功",service.batchOrderSave(batchOrderSavaDto));
	 }
	/**
	 *  编辑
	 *
	 * @param busRoomBookingOrders
	 * @return
	 */
	@AutoLog(value = "酒店预定订单-编辑")
	@ApiOperation(value="酒店预定订单-编辑", notes="酒店预定订单-编辑")
	//@RequiresPermissions("business:bus_room_booking_orders:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<Boolean> edit(@RequestBody BookingOrderEditVo busRoomBookingOrders) {
		return Result.OK("编辑预定成功",service.editBooking(busRoomBookingOrders));
	}

	 /**
	  *   酒店预定订单-通过id获取订单详情
	  *
	  * @param
	  * @return
	  */
//	 @AutoLog(value = "酒店预定订单-通过id获取订单详情")
	 @ApiOperation(value="酒店预定订单-通过id获取订单详情", notes="酒店预定订单-通过id获取订单详情")
	 //@RequiresPermissions("business:bus_room_booking_orders:getBookingOrderInfo")
	 @GetMapping(value = "/getBookingOrderInfo")
	public Result<BookingOrderEditVo> getBookingOrderInfo(String bookingOrderId,String bookingNo) {
		 BookingOrderEditVo reuslt =  service.getBookingInfoById(bookingOrderId, bookingNo);
	 	return Result.ok(reuslt);
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "酒店预定订单-通过id删除")
	@ApiOperation(value="酒店预定订单-通过id删除", notes="酒店预定订单-通过id删除")
	//@RequiresPermissions("business:bus_room_booking_orders:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		service.removeOrder(id);
		return Result.OK("删除成功!");
	}

	 /**
	  *   设置状态
	  *
	  * @param order
	  * @return
	  */
	 @AutoLog(value = "酒店预定订单-设置状态")
	 @ApiOperation(value="酒店预定订单-设置状态", notes="酒店预定订单-设置状态")
	 //@RequiresPermissions("business:bus_room_booking_orders:delete")
	 @PostMapping(value = "/set-booking-status")
	 public Result<String> delete(@RequestBody BusRoomBookingOrders order) {
		 service.setOrderStatus(order);
		 return Result.OK("设置成功!");
	 }

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "酒店预定订单-批量删除")
	@ApiOperation(value="酒店预定订单-批量删除", notes="酒店预定订单-批量删除")
	//@RequiresPermissions("business:bus_room_booking_orders:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		service.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "酒店预定订单-通过id查询")
	@ApiOperation(value="酒店预定订单-通过id查询", notes="酒店预定订单-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<BusRoomBookingOrders> queryById(@RequestParam(name="id",required=true) String id) {
		BusRoomBookingOrders busRoomBookingOrders = service.getById(id);
		if(busRoomBookingOrders==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(busRoomBookingOrders);
	}


	 /**
	  * 酒店预定订单-通过批次id查询批次订单信息
	  * @param batchId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-通过批次id查询批次订单信息", notes="酒店预定订单-通过批次id查询批次订单信息")
    @RequestMapping(value = "batch-order-detail",method = RequestMethod.GET)
	 public  Result<BatchOrderEditVo> getBatchOrder(String batchId) {
    	return  Result.ok(service.batchOrderDetail(batchId));
	 }


	 /**
	  * 设置预约订单批次单状态
	  * @param
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-设置预约订单批次单状态", notes="酒店预定订单-设置预约订单批次单状态")
	 @RequestMapping(value = "set-batch-order-status",method = RequestMethod.POST)
	 public  Result<Boolean> setBatchOrderStatus(BusBookingBatch batch) {
		 return  Result.ok(service.setBatchOrderStatus(batch));
	 }

	 /**
	  * 预约房间入住
	  * @param
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-预约房间入住", notes="酒店预定订单-预约房间入住")
	 @RequestMapping(value = "booking-to-live",method = RequestMethod.POST)
	 public  Result<String> bookingRoomToLive(String bookingRoomId, @RequestBody List<BusLivingCustomer> customers,String hotelId) {
		 return Result.OK("入住成功",service.bookingToLive(bookingRoomId, customers,hotelId,true,null,null));
	 }

	 /**
	  * 入住
	  * @param
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-入住", notes="酒店预定订单-入住")
	 @RequestMapping(value = "living",method = RequestMethod.POST)
	 public  Result<String> living(@RequestBody BookingOrderSaveDto param, String hotelId) {
		 Boolean isTeam = param.getOrderInfo().getBookingOrdersType().equals(2);
		 param.getOrderInfo().setBookingOrdersType(1);
		 return  Result.OK("入住成功",service.customerLiving(param,isTeam,hotelId));
	 }

	 /**
	  * 获取入住订单费用账单
	  * @param bookingOrderId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-获取入住订单费用账单", notes="酒店预定订单-获取入住订单费用账单")
	 @RequestMapping(value = "/living-fees",method = RequestMethod.GET)
	 public Result getLivingOrderFees(String bookingOrderId, Boolean isAllFee) {
	 	if(bookingOrderId == null || bookingOrderId.isEmpty()) throw new JeecgBootException("参数错误");
	 	return Result.ok(service.getLivingOrderFee(bookingOrderId, isAllFee));
	 }

	 /**
	  * 续住/提前
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-续住/提前", notes="酒店预定订单-续住/提前")
	 @GetMapping(value = "/get-continue-order")
	 public Result<List<LivingContinueVo>> getContinueOrder(String bookingOrderId , String hotelId) {
		 List<LivingContinueVo> livingContinueList = service.getContinueOrder(bookingOrderId, hotelId);
		 return Result.OK(livingContinueList);
	 }
	 /**
	  * 续住前判断是否被预约
	  */
	 @ApiOperation(value="续住前判断是否被预约", notes="续住前判断是否被预约")
	 @RequestMapping(value = "/isBooked",method = RequestMethod.POST)
	 public Result isBooked(@RequestBody List<LivingContinueVo> livingContinueList){
		 List<LivingContinueVo> returnLivingContinues = service.roomIdBooked(livingContinueList);
		 return returnLivingContinues == null ? Result.error("未找到订单") : Result.ok(returnLivingContinues);
	 }

	 /**
	  * 续住/提前
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-续住/提前", notes="酒店预定订单-续住/提前")
	 @RequestMapping(value = "/continue-living",method = RequestMethod.POST)
	 public Result<Boolean> continueLiving(@RequestBody List<LivingContinueVo> livingContinueList,String hotelId) {
		 Boolean isOk = service.continueLiving2(livingContinueList, hotelId);
		 return Result.OK(isOk);
	 }

	 /**
	  * 全部结账
	  * @param bookingOrderId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-全部结账", notes="酒店预定订单-全部结账")
	 @RequestMapping(value = "/settle-checkout",method = RequestMethod.POST)
	 public Result<Boolean> settleCheckout(@RequestBody List<BusOrderFee> fees, String bookingOrderId) {
		 fees.forEach(e -> e.setIsSettleFee(true));
		 Boolean isOk = service.settleBillCheckOut(fees,bookingOrderId);
		 return Result.OK(isOk);
	 }

	 /**
	  * 单房结账
	  * @param livingOrderId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-单房结账", notes="酒店预定订单-单房结账")
	 @RequestMapping(value = "/living-settle-checkout",method = RequestMethod.POST)
	 public Result<Boolean> livingSettleBillCheckOut(@RequestBody List<BusOrderFee> fees, String livingOrderId) {
		 fees.forEach(e -> e.setIsSettleFee(true));
		 Boolean isOk = service.livingSettleBillCheckOut(fees,livingOrderId);
		 return Result.OK(isOk);
	 }


	 /**
	  * 部分结账
	  * @param param
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-部分结账", notes="酒店预定订单-部分结账")
	 @RequestMapping(value = "/partial-settle",method = RequestMethod.POST)
	 public Result<Boolean> partialSettle (@RequestBody PartialSettleVo param) {
	 	return Result.OK(service.partialSettle(param));
	 }

	 /**
	  * 拆分房间
	  * @param livingOrderId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-拆分房间", notes="酒店预定订单-拆分房间")
	 @RequestMapping(value = "/split-living",method = RequestMethod.POST)
	 public Result<Boolean> splitLiving(String livingOrderId) {
		 String bookingOrdersId = service.splitLiving(livingOrderId);
		 return Result.OK(bookingOrdersId);
	 }

	 /**
	  * 先走不结
	  * @param livingOrderId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-先走不结", notes="酒店预定订单-先走不结")
	 @RequestMapping(value = "/leave-not-settle",method = RequestMethod.POST)
	 public Result<Boolean> leaveNotSettle(String bookingOrderId,String livingOrderId){
		 Boolean isOk = service.leaveNotSettle(bookingOrderId,livingOrderId);
		 return Result.OK(isOk);
	 }

	 /**
	  * 撤销先走不结
	  */
	 @ApiOperation(value="撤销先走不结", notes="撤销先走不结")
	 @RequestMapping(value = "/cancel-leave-not-settle",method = RequestMethod.POST)
	 public Result<Boolean> cancelLeaveNotSettle(String bookingOrderId,String livingOrderId){
		 Boolean isOk = service.cancelLeaveNotSettle(bookingOrderId,livingOrderId);
		 return Result.OK(isOk);
	 }

	 /**
	  * 撤销先走不结
	  */
	 @ApiOperation(value="撤销结账", notes="撤销结账")
	 @RequestMapping(value = "/cancel-leave-settle",method = RequestMethod.POST)
	 public Result<Boolean> cancelLeaveSettle(String bookingOrderId,String livingOrderId){
		 Boolean isOk = service.cancelLeaveSettle(bookingOrderId,livingOrderId);
		 return Result.OK(isOk);
	 }

	 /**
	  * 获取入住订单
	  * @param status
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-获取入住订单", notes="酒店预定订单-获取入住订单")
	 @RequestMapping(value = "/living-orders",method = RequestMethod.GET)
	 public Result<IPage<RoomLivingQueryVo>> livingOrders(Page<RoomLivingQueryVo> page, String keyw, Integer status,String hotelId){
		 return Result.OK(service.getLivingPageData(status,keyw,page,hotelId));
	 }

	 /**
	  * 获取可联房入住订单列表
	  * @param status
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-获取入住订单", notes="酒店预定订单-获取入住订单")
	 @RequestMapping(value = "/union-living-orders",method = RequestMethod.GET)
	 public Result<IPage<RoomLivingQueryVo>> unionLivingOrders(Page<RoomLivingQueryVo> page, String keyw, Integer status,String hotelId){
		 return Result.OK(service.getUnionLivingPageData(keyw,page,hotelId));
	 }



	 /**
	  * 新增收费项目
	  * @param orders
	  * @param livingOrderId
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-新增收费项目", notes="酒店预定订单-新增收费项目")
	 @RequestMapping(value = "/set-living-order-fee",method = RequestMethod.POST)
	 @Transactional(rollbackFor = Exception.class)
	 public Result<Boolean> setLivingOrderFee(@RequestBody List<BusOrderFee> orders, String livingOrderId,String hotelId){
	 	return Result.OK(service.setLivingOrderFee(orders,livingOrderId,hotelId));
	 }

	 /**
	  * 
	  * @return
	  */
	 @ApiOperation(value="退单", notes="退单")
	 @RequestMapping(value = "/tuidan",method = RequestMethod.POST)
	 public Result<Boolean> tuidan(@RequestBody List<String> feeIds){
		 return Result.OK(service.tuidan(feeIds));
	 }
	 /**
	  * 添加联房
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-添加联房", notes="酒店预定订单-添加联房")
	 @RequestMapping(value = "/union-order",method = RequestMethod.POST)
	 public Result<Boolean> unionOrder(String roomId,String targetRoomId,String bookingOrderId, String hotelId) {
	 	return Result.OK(service.unionOrder(roomId,targetRoomId,bookingOrderId,hotelId));
	 }

	 /**
	  * 合并联房
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-合并联房", notes="酒店预定订单-合并联房")
	 @RequestMapping(value = "/merge-order",method = RequestMethod.POST)
	 public Result<Boolean> mergeOrder(String hotelId, String livingRoomId,@RequestBody List<String> livingOrderIds ){
	 	return  Result.OK(service.mergeOrder(hotelId,livingRoomId,livingOrderIds));
	 }

	 /**
	  * 合并联房
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-合并联房", notes="酒店预定订单-合并联房")
	 @RequestMapping(value = "/merge-order2",method = RequestMethod.POST)
	 public Result<Boolean> mergeOrder2(String hotelId, String livingRoomId,@RequestBody List<String> livingOrderIds ){
		 return  Result.OK(service.mergeOrder(hotelId,livingRoomId,livingOrderIds));
	 }

	 /**
	  * 远期房态
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-远期房态", notes="酒店预定订单-远期房态")
	 @RequestMapping(value = "/forward-fangtai",method = RequestMethod.GET)
	 public Result<ForwardFangTaiVo> forwardFangTai(
	 		Boolean isContainLeave,
	 		String start,
			String end,String hotelId) {
	 	return  Result.OK(service.forwardFangTai(start,end,hotelId,isContainLeave));
	 }

	 /**
	  * 日历房态
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-日历房态", notes="酒店预定订单-日历房态")
	 @RequestMapping(value = "/rili-fangtai",method = RequestMethod.GET)
	 public Result<RiLiFangTaiResultVo> riliFangTai(
			 String start,
			 String end,String hotelId) {
		 return  Result.OK(service.riliFangTai(start,end,hotelId));
	 }

	 /**
	  * 客單
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-客历", notes="酒店预定订单-客历")
	 @RequestMapping(value = "/kedan-orders",method = RequestMethod.GET)
	 public Result<IPage<KeLiItemVo>> keli(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
										   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
										   KedanOrderDto kedanOrderDto){
	 	if(kedanOrderDto.getType() == null) throw new JeecgBootException("参数错误");
	 	if(kedanOrderDto.getType() == 1 && kedanOrderDto.getLivingStatus()  == null ) throw new JeecgBootException("参数错误");
	 	if(kedanOrderDto.getType() == 2 && kedanOrderDto.getBookingStatus() == null) throw new JeecgBootException("参数错误");
		 Page<KeLiItemVo> page = new Page<KeLiItemVo>(pageNo, pageSize);
	 	if(kedanOrderDto.getType() == 1 ) return Result.OK(service.getLivingOrderKL(page, kedanOrderDto));
	 	if(kedanOrderDto.getType() == 2) return  Result.OK(service.getBookingOrderKL(page, kedanOrderDto));
	 	return  null;
	 }

	 /**
	  * 修改订单信息
	  * @param info 修改的信息
	  * @param type 1 预约单 2 入住单
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-修改订单信息", notes="酒店预定订单-修改订单信息")
	 @RequestMapping(value = "/update-orders",method = RequestMethod.POST)
	 public Result<Boolean> updateOrderInfo(Integer type,@RequestBody UpdateOrderInfoDto info) {
	 	return Result.OK(service.updateOrderInfo(type,info));

	 }

	 /**
	  * 入住改价
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-入住改价", notes="酒店预定订单-入住改价")
	 @RequestMapping(value = "/update-order-price",method = RequestMethod.POST)
	 public Result<Boolean> updateOrderPrice(@RequestBody UpdateOrderPriceDto info) {
		 return Result.OK(service.updateOrderPrice(info));
	 }

	 /**
	  * 结账调价
	  * @return
	  */
	 @ApiOperation(value="酒店结账界面-调价", notes="酒店结账界面-调价")
	 @RequestMapping(value = "/batch-update-order-price",method = RequestMethod.POST)
	 public Result<Boolean> batchUpdateOrderPrice(@RequestBody List<UpdateOrderPriceDto> infos) {
		 return Result.OK(service.batchUpdateOrderPrice(infos));
	 }

	 /**
	  * 同步房间ORDER
	  * @return
	  */
	 @ApiOperation(value="酒店预定订单-同步房间ORDER", notes="酒店预定订单-同步房间ORDER")
	 @RequestMapping(value = "/sync-order-status",method = RequestMethod.GET)
	 public  Result syncLivingOrderStatus() {
	 	service.syncDayOrderFee();
	 	return Result.OK();
	 }

	 @ApiOperation(value="根据手机号查询入住历史列表", notes="根据手机号查询入住历史列表")
	 @RequestMapping(value = "/ruzhu-history-list",method = RequestMethod.GET)
	 public Result<IPage<HashMap<String, Object>>> ruZhuHistoryList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
																	@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,@RequestParam(name = "hotelId") String hotelId,@RequestParam(name = "phone") String phone) {
		 Page<HashMap<String, Object>> page = new Page<HashMap<String, Object>>(pageNo, pageSize);
		 return Result.OK(service.ruZhuHistoryList(page, hotelId, phone));
	 }

	 @ApiOperation(value="根据手机号查询入住历史列表", notes="根据手机号查询入住历史列表")
	 @RequestMapping(value = "/del-bus-data",method = RequestMethod.GET)
	 public  Result<String> delBusData(String hotelId) {
	 	return Result.OK(service.delBusData(hotelId));
	 }


	 @ApiOperation(value="换房", notes="换房")
	 @RequestMapping(value = "/change-living-room",method = RequestMethod.POST)
	 public  Result<Boolean> changeRoom(@RequestBody LivingContinueVo param) {
		 return Result.OK(service.changeLivingRoom(param));
	 }

	 @ApiOperation(value="撤销", notes="撤销")
	 @RequestMapping(value = "/reverse-living",method = RequestMethod.GET)
	 public  Result<Boolean> reverseLiving(String livingOrderId,String hotelId) {
	 	return  Result.OK(service.reverseLiving(livingOrderId,hotelId));
	 }

//
//	 @ApiOperation(value="联房数量", notes="联房数量")
//	 @RequestMapping(value = "/bookingOrdersCount",method = RequestMethod.GET)
//	 public  Result<Long> bookingOrdersCount(String bookingOrderId,String hotelId) {
//		 busRoomBookingOrdersService.count(bookingOrderId, hotelId);
//
//		 return  Result.OK(busRoomBookingOrdersService.count(bookingOrderId, hotelId));
//	 }
	 @ApiOperation(value="是否可以单独结算", notes="联房数量")
	 @RequestMapping(value = "/canOnlyPaySelf",method = RequestMethod.GET)
	 public  Result<Boolean> canOnlyPaySelf(String bookingOrderId, String hotelId, String roomId) {
		 Boolean onlyPaySelf = service.canOnlyPaySelf(bookingOrderId, hotelId, roomId);
		 return  Result.OK(onlyPaySelf);
	 }

	 @ApiOperation(value="结算部分费用", notes="联房数量")
	 @RequestMapping(value = "/payPortionFee",method = RequestMethod.POST)
	 public  Result<Boolean> payPortionFee(@RequestBody List<String> feeIds) {
		 Boolean onlyPaySelf = service.payPortionFee(feeIds);
		 return  Result.OK(onlyPaySelf);
	 }

	 @ApiOperation(value = "修改房间状态", notes = "修改房间状态")
	 @GetMapping(value = "/changeState")
	 public Result<String> changeState(BusRoomsLivingOrder roomsLivingOrder){
		 boolean update = roomsLivingOrderService.updateById(roomsLivingOrder);
		 System.out.println(roomsLivingOrder);
		 return update ? Result.OK("修改房态成功") : Result.error("修改房态失败");
	 }

	 /**
	  * 导出excel
	  *
	  * @param request
	  * @param busRoomBookingOrders
	  */
	 //@RequiresPermissions("business:bus_room_booking_orders:exportXls")
	 @RequestMapping(value = "/exportXls")
	 public ModelAndView exportXls(HttpServletRequest request, BusRoomBookingOrders busRoomBookingOrders) {
		 return super.exportXls(request, busRoomBookingOrders, BusRoomBookingOrders.class, "酒店预定订单");
	 }

	 /**
	  * 通过excel导入数据
	  *
	  * @param request
	  * @param response
	  * @return
	  */
	 //@RequiresPermissions("business:bus_room_booking_orders:importExcel")
	 @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	 public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		 return super.importExcel(request, response, BusRoomBookingOrders.class);
	 }

	 @Resource
	 BusRoomBookingOrdersMapper baseMapper;

	 @RequestMapping(value = "/exportXls2")
	 public ModelAndView exportXls2(HttpServletRequest request,
								   @RequestParam(name="startTime" ,required=false) @JsonFormat(pattern = "yyyy-MM-dd")  @DateTimeFormat(pattern="yyyy-MM-dd") DateTime startTime,
								   @RequestParam(name="endTime" ,required=false) @JsonFormat(pattern = "yyyy-MM-dd")  @DateTimeFormat(pattern="yyyy-MM-dd") DateTime endTime,
								   KedanOrderDto kedanOrderDto) {
		 Page<KeLiItemVo> page = new Page<>(1,9999999);
		 IPage<KeLiItemVo> pRes = new Page<>();
		 String title = "";
		 if (kedanOrderDto.getType() == 1){
			 title = "入住单";
			 pRes = baseMapper.getKeLiLiving(page, kedanOrderDto);
			 Set<String> customerSourceId = pRes.getRecords().stream().map(KeLiItemVo::getCustomerSource).collect(Collectors.toSet());
			 List<BusDictItem> customerSourceList = busDictItemService.listByIds(customerSourceId);
			 pRes.getRecords().forEach(e -> {
				 Optional<BusDictItem> dictItem = customerSourceList.stream().filter(source -> (source.getId().equals(e.getCustomerSource()))).findFirst();
				 dictItem.ifPresent(source -> e.setCustomerSource(source.getItemText()));
				 e.setCustomerTypeText(Objects.requireNonNull(CustomerTypeEnum.val(e.getCustomerType())).getTitle());
				 e.setOTypeText(Objects.requireNonNull(LivingTypeEnum.val(e.getOType())).getTitle());
				 e.setStatusText(Objects.requireNonNull(SettleTypeEnum.val(e.getSettleType())).getTitle());
				 e.setConsumerText(e.getYushou().subtract(e.getYuE()));
			 });
		 } else if (kedanOrderDto.getType() == 2){
			 title = "预约单";
			 pRes = baseMapper.getKeBooking(page, kedanOrderDto);
			 Set<String> customerSourceId = pRes.getRecords().stream().map(KeLiItemVo::getCustomerSource).collect(Collectors.toSet());
			 List<BusDictItem> customerSourceList = busDictItemService.listByIds(customerSourceId);
			 pRes.getRecords().forEach(e -> {
				 Optional<BusDictItem> dictItem = customerSourceList.stream().filter(source -> (source.equals(e.getCustomerSource()))).findFirst();
				 dictItem.ifPresent(source -> e.setCustomerSource(source.getItemText()));e.setCustomerTypeText(CustomerTypeEnum.val(e.getCustomerType()).getTitle());
				 e.setOTypeText(Objects.requireNonNull(LivingTypeEnum.val(e.getOType())).getTitle());
				 String status = "";
				 if (Objects.equals(e.getBookingStatus(), BookingStatusTypeEnum.NORMAL.getKey())) {
					 if (StrUtil.isNotEmpty(e.getLivingId())){
						 status = CommonConstant.LIVING;
					 } else {
						 status = e.getArrivalTime().after(new Date()) ? CommonConstant.BOOKING : CommonConstant.WILL_EXPIRE;
					 }
				 } else if (BookingStatusTypeEnum.val(e.getBookingStatus()) != null){
					 status = Objects.requireNonNull(BookingStatusTypeEnum.val(e.getBookingStatus())).getTitle();
				 }
				 e.setStatusText(status);
			 });
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, title);
		 mv.addObject(NormalExcelConstants.CLASS, KeLiItemVo.class);
		 //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		 ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + 123, title);
		 exportParams.setImageBasePath(upLoadPath);
		 //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		 mv.addObject(NormalExcelConstants.PARAMS,exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, pRes.getRecords());
		 return mv;
	 }


 }
